#coding=utf-8

import unittest
from selenium import webdriver
from appium import webdriver
from time import sleep
from nav_plugin_op import nav_plugin_factory
from selenium.common.exceptions import WebDriverException
import os
from Public import BasePage
from Tool.usefulTools import userfulToolsFactory
from Public.BasePage import element_Oprate
from Public.BasePage import BasicAction
from Public import BaseConstant

#实例化基础数据
navOpenFactory = nav_plugin_factory()
userfulTool = userfulToolsFactory()
element_oprate_instance = element_Oprate()
basicAction = BasicAction()
My_work_Paramter_instances = BaseConstant.My_work_Paramter
# nav_name = "工作"
# plugin_name = "我的工作"	
nav_name = ["导航栏工作",'xpath',"//android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.FrameLayout/android.widget.RadioButton"]
plugin_name = ["插件列表-我的工作",'name','我的工作']

class my_work_factory():

	def open_mywork_plug(self,driver,file_path):
		try:
			# 点击工作的导航，打开工作列表
			element_oprate_instance.element_click(nav_name,file_path)
			# 点击"通用查询"的插件，打开插件
			element_oprate_instance.element_click(plugin_name,file_path)
			#等待通用查询页面内容进行加载，加载完成之后进行页面确认并界面
			element_oprate_instance.element_save_pic(file_path, 'open_mywork_plug_successful')

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'open_mywork_plug_fail')
			raise

	def punch_the_clock(self,driver,file_path):
		try:
			#打卡上班
			sleep(5)
			element_oprate_instance.element_click(My_work_Paramter_instances.btn_duty_id, file_path)
			element_oprate_instance.element_click(My_work_Paramter_instances.confirm_btn_id, file_path)
			sleep(10)
			#打卡下班
			element_oprate_instance.element_click(My_work_Paramter_instances.btn_duty_id, file_path)
			element_oprate_instance.element_click(My_work_Paramter_instances.confirm_btn_id, file_path)
			element_oprate_instance.element_save_pic(file_path, 'punch_the_clock_successful')
			# element_oprate_instance.element_click(My_work_Paramter_instances.exit_name, file_path)
		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'punch_the_clock_fail')
			raise

	def today_track(self,driver,file_path):
		try:
			#轨迹回放
			element_oprate_instance.element_click(My_work_Paramter_instances.menu_list_id, file_path)
			element_oprate_instance.element_click(My_work_Paramter_instances.track_id, file_path)
			element_oprate_instance.element_save_pic(file_path,'今日轨迹点击效果')
			sleep(5)
			element_oprate_instance.element_click(My_work_Paramter_instances.map_track_id, file_path)
			sleep(2)
			element_oprate_instance.element_save_pic(file_path, 'today_track_successful')
			element_oprate_instance.element_click(My_work_Paramter_instances.exit_id, file_path)
			element_oprate_instance.element_click(My_work_Paramter_instances.exit_id, file_path)

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'punch_the_clock_fail')
			print u'由于无轨迹数据导致的失败'
			raise

if __name__ == '__main__':
	unittest.main()					
